const basicAuth = require('basic-auth')
const jwt = require('jsonwebtoken')
const { security } = require('../config')
class Auth {
  constructor(level) {
    // 颁发令牌时需要 把权限信息也带入进去，验证权限时，可以取到
    this.level = level

    Auth.USER = 8
    Auth.ADMIN = 16
    Auth.SUPER_ADMIN = 32
  }
  // 作为中间件验证token
  get m() {
    return async (ctx, next) => {}
  }
  // 验证token
  static verifyToken() {}
  // 生成token
  static genToken(id, level) {
    const { secret, expiresIn } = security
    const token = jwt.sign(
      {
        id,
        level,
      },
      secret,
      {
        expiresIn,
      }
    )
    return token
  }
}

module.exports = Auth
